﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Data;
using DataProvider;

namespace SGBDSecurity
{
    public partial class ViewTable2 : Form
    {
        UserDataProvider aUserDataProvider;
        User aUser;
        Table aTable;
        TableData aTableData;

        public ViewTable2(User iUser, Table iTable)
        {
            aTable = iTable;
            aUser = iUser;
            aUserDataProvider = new UserDataProvider();
            InitializeComponent();
            aTableData = aUserDataProvider.GetViewTable(aUser, aTable);
            this.lNome.Text = iUser.Login;
            this.lNivel.Text = iUser.Classe + "";

            foreach (string temp in aTableData.Colunas)
            {
                DataGridViewColumn column = new DataGridViewColumn();
                column.HeaderText = temp;
                column.CellTemplate = new DataGridViewTextBoxCell();
                dataGridView1.Columns.Add(column);
            }

            for (int j = 0; j < aTableData.Valores.Count / aTableData.Colunas.Count; j++)
            {
                dataGridView1.Rows.Add(aTableData.Valores.GetRange(j * aTableData.Colunas.Count, aTableData.Colunas.Count).ToArray());
            }
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
